﻿#if __ANDROID__
using System;
using System.Windows.Input;
using Xamarin.Forms;
#endif

namespace Moven.Controls
{
	public class NativeCheckBox: 
	#if __ANDROID__
	View
	#elif __IOS__
	CheckBox
	#endif
	{
		#if __ANDROID__
		static readonly Type SelfType = typeof(NativeCheckBox);

		public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(
			nameof(IsChecked), typeof(bool), SelfType, false);

		public static readonly BindableProperty ToggleCommandProperty = BindableProperty.Create(
			nameof(ToggleCommand), typeof(ICommand), SelfType);

		public bool IsChecked
		{
			get { return (bool)GetValue(IsCheckedProperty); }
			set 
			{ 
				SetValue(IsCheckedProperty, value);
				ToggleCommand?.Execute(null);
			}
		}

		public ICommand ToggleCommand
		{
			get { return (ICommand)GetValue(ToggleCommandProperty); }
			set { SetValue(ToggleCommandProperty, value); }
		}
		#endif
	}
}
